package com.example.mobile_ui;


import com.example.mobile_function.SysApplication;
import com.example.mobile_moudle.ExampleApplication;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.Toast;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.RelativeLayout;
import android.widget.TabHost;



public class MainActivity extends TabActivity {
	TabHost tabHost;
	TabHost.TabSpec tabSpec;
	RadioGroup radioGroup;
	RelativeLayout bottom_layout;
	int startLeft;
	ImageView img;
	String strGang;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		try {
			requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);  
			setContentView(R.layout.activity_main);
			getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.table_titlebar); 
			bottom_layout = (RelativeLayout) findViewById(R.id.layout_bottom);

			SysApplication.getInstance().addActivity(this);
			
            //strGang= ""; 
			//Bundle bundle = new Bundle();
//			Intent intent = getIntent();
//			Bundle bundle = intent.getExtras();
//			strGang  = bundle.getString("gang");
//			
//			final ExampleApplication app = (ExampleApplication)getApplication();
//			app.setstrGang(strGang);
			
//			final ExampleApplication app = (ExampleApplication)getApplication();
//			strGang= app.getstrGang();
			
			tabHost = getTabHost();
			tabHost.addTab(tabHost.newTabSpec("salesplan").setIndicator("SalesPlan").setContent(new Intent(this, SalesPlanActivity.class)));
			tabHost.addTab(tabHost.newTabSpec("infosign").setIndicator("InfoSign").setContent(new Intent(this, InfoSignActivity.class)));
			tabHost.addTab(tabHost.newTabSpec("salescar").setIndicator("SalesCar").setContent(new Intent(this, SalesCarActivity.class)));
			tabHost.addTab(tabHost.newTabSpec("more").setIndicator("More").setContent(new Intent(this, MoreActivity.class)));
			
			radioGroup = (RadioGroup) findViewById(R.id.radiogroup);
			radioGroup.setOnCheckedChangeListener(checkedChangeListener);
			
			img = new ImageView(this);
			img.setImageResource(R.drawable.maintab_toolbar_bg);
		} catch (Exception e) {
			Toast.makeText(MainActivity.this, e.getMessage(),Toast.LENGTH_SHORT).show();
		}

	}
	
	
	private OnCheckedChangeListener checkedChangeListener = new OnCheckedChangeListener() {

		@Override
		public void onCheckedChanged(RadioGroup group, int checkedId) {
			switch (checkedId) {
			case R.id.radio_plan:
				tabHost.setCurrentTabByTag("salesplan");
				startLeft = 0;
				break;
			case R.id.radio_sign:
				tabHost.setCurrentTabByTag("infosign");
				startLeft = img.getWidth();
				break;
			case R.id.radio_car:
				tabHost.setCurrentTabByTag("salescar");
				startLeft = img.getWidth() * 2;
				break;
			case R.id.radio_more:
				tabHost.setCurrentTabByTag("more");
				startLeft = img.getWidth() * 3;
				break;
			default:
				break;
			}
		}
	};
}
